const {Print} = require('../print/print');

/**
 * 时间戳 转换 时间字符串 1704678211708 => "2024-01-18"
 * @param {number} timestamp 时间戳
 * @param strFormat 时间字符串格式
 * @returns {string}
 */
const dateFormat = (timestamp, strFormat = "YYYY-MM-DD") => {
	let result = '';
	const myDate = new Date(+timestamp);
	const YYYY = myDate.getFullYear() + "";
	const MM = ("00" + (myDate.getMonth() + 1)).slice(-2);
	const DD = ("00" + myDate.getDate()).slice(-2);
	const hh = ("00" + myDate.getHours()).slice(-2);
	const mm = ("00" + myDate.getMinutes()).slice(-2);
	const ss = ("00" + myDate.getSeconds()).slice(-2);
	result = strFormat
		.replace(/YYYY/, YYYY)
		.replace(/MM/, MM)
		.replace(/DD/, DD)
		.replace(/hh/, hh)
		.replace(/mm/, mm)
		.replace(/ss/, ss);
	return result;
}

const printTime = (msg, startTime, endTime) => {
	const durTime = Math.floor((endTime - startTime) / 1000);
	const m = Math.floor(durTime / 60);
	const s = durTime % 60;
	Print.success(`${msg}: ${m}分 ${s}秒`);
	return { m, s };
};
// 2024-05-14T10:00:00Z
const version = dateFormat(+new Date(),'YYYY-MM-DDThh:mm:ssZ', )


module.exports = {
    dateFormat,
	printTime,
	version,
};